matplotlib figure layout
Tips
hr.icon
Figure
hr.icon
Zorder
図の重ね合わせの順番を変える
pylab_examples example code: zorder_demo.py
hr.icon
Room
Move the edge of an axes to make room for tick labels
Automatically make room for tick labels
Fig size
MetPy Mondays '#128 - Sizing Figures for Publication : Unidata Developer's Blog Figures - American Meteorological Society
DPI
code:python
# When figure is created
fig,ax=plt.subplots(figuresize=(12,10),dpi=3000)
# Set parameters globally for all figures
# when saving a figure
plt.savefig("foo.png",dpi=300)
Title
/icons/hr.icon
Making Subplot
subplot
make subplot once at a time
subplots
make subplots all at once
subplot2grid()
Create an axis at specific location inside a regular grid.
subplot
code:python
plt.subplot(3,1,1)
plt.subplot(3,1,2)
plt.subplot(3,1,3)
subplots
prepare subplots
only 1 subplot
code:python
fig, ax = plt.subplots()
code:python
fig,axes=plt.subplots(3,3,figsize=8.27,11.69,subplot_kw={'projection': ccrs.PlateCarree()}) flatten axes
code:python
fig,axes=plt.subplots(3,3)
axes=axes.flatten()
flatten axes
code:python
for ax, df_key in zip(axes.flatten(), imputations):
....
remove last subplot
code:python
axlast.remove()
MetPy Mondays '#102: Using Dictionaries to Store Plotting Parameters : Unidata Developer's Blog MetPy Mondays `#124 - Aligning Labels in Matplotlib : Unidata Developer's Blog code:python
fig.align_labels()
Align y-labels
MetPy Mondays `#118 - Legends and Subplots : Unidata Developer's Blog
Examples on google collaboratory
GridSpec
Customizing Location of Subplot Using GridSpec
AxesGrid
subplot_mosaic
/icons/hr.icon
Adjust Subplots
subplots_adjust
Tight Layout
Constrained Layout
The constrained layout and tight layout are two options available for layout management in Matplotlib. Constrained layout automatically adjusts the positions of subplots to fit their contents within the figure while avoiding overlaps. This is useful for creating complex plots with multiple subplots that would otherwise require manual adjustments.
On the other hand, tight layout adjusts the spacing between subplots to fit them within the figure without overlapping. However, this can sometimes result in elements being pushed too close, making them difficult to read.
In general, constrained layout is recommended when working with complex plots with multiple subplots, while tight layout may be more appropriate for simpler plots where readability is a priority. Ultimately, the choice between these two options depends on the specific needs of the visualization and the personal preferences of the user.
/icons/hr.icon
Inset Axes
Zoom region inset axes
MetPy Mondays `#120 - Inset Axes with RADAR data : Unidata Developer's Blog python - Cartopy coastlines hidden by inset_axes use of Axes.pie - Stack Overflow
python - embed small map (cartopy) on matplotlib figure - Stack Overflow
hr.icon
Examples
python - matplotlib write text in the margin - Stack Overflow
Matplotlib の多くのサブプロットでサブプロットのサイズまたは間隔を改善する方法 | Delft スタック
See also